<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="keywords" content="天地图"/>
    <title>天地图－地图API－范例－画布覆盖物类</title>
    <script src="http://api.tianditu.gov.cn/api?v=4.0&tk=95f0a5688ec713adb3dd1735533f6fcb"></script>
    <script src="./CanvasOverlay.js"></script>
    <script>
    var zoom = 17;
    var size = 100;

    function onLoad() {
        // 添加地图
        var map = new T.Map('mapDiv');
        map.centerAndZoom(new T.LngLat(106.68243, 26.22207), zoom);

        // 添加画布图层
        var point = [ 106.68243, 26.22207 ];
        var layer = new T.CanvasOverlay(draw, { opacity: 1, point, size });
        map.addOverLay(layer);
    }
    function draw(ctx, size, radium = 0) {
        const maxRadium = size / 2;
        ctx.clearRect(0, 0, size, size);
        ctx.fillStyle = 'rgb(0, 100, 255)';
        ctx.strokeStyle = 'white';
        ctx.globalAlpha = 1;
        ctx.lineWidth = 2;
        ctx.globalAlpha = (ctx.globalAlpha - 0.01 + 1) % 1;
        radium = (radium + 1) % maxRadium;
        ctx.beginPath();
        ctx.arc(maxRadium, maxRadium, radium, 0, 2 * Math.PI);
        ctx.fill();
        ctx.stroke();
        window.requestAnimationFrame(function(){
            draw(ctx, size, radium);
        });
    }
    </script>
</head>
<body onLoad="onLoad()">
    <div id="mapDiv" style="position:absolute;width:100%; height:100%"></div>
</body>
</html>
